//A – 众数问题
// 6 1 2 2 2 3 
// 2 3
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int tong[maxn];
int main(int argc, char const *argv[]){
    int n;
    cin >>n;
    for (int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        tong[x]++;
        
    }
    int Max = -1, ans;
    for (int i=0;i<maxn; i++){
        if (Max < tong[i]){
            Max  = tong[i];
            ans = i;
            
        }
    }
    printf("%d\n%d\n",ans,Max);
    return 0;
}





//B – 整数因子分解问题*
//12 
//8 
#include <bits/stdc++.h>
const int maxn = 1e7 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
LL dp[maxn];
LL dfs(LL x) {
    if (x < maxn && dp[x]) return dp[x];
    LL cnt = 1;
    for (LL i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            cnt += dfs(i);
            if (i * i != x) cnt += dfs(x / i);
        }
    }
    if (x < maxn) dp[x] = cnt;
    return cnt;
}
 
int main(int argc, char const *argv[]) {
    LL x;
    cin >> x;
    printf("%lld", dfs(x));
    return 0;
}



//C – 顺序表应用7：最大子段和之分治递归法*
//6     -2 11 -4 13 -5 -2 
//20 11 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int a[maxn];
int cnt;
int dfs(int l, int r) {
    cnt++;
    if (l == r) {
        return max(a[l], 0);
    }
    int mid = l + r >> 1;
    int sum = -1;
    sum = max(dfs(l, mid), sum);
    sum = max(dfs(mid + 1, r), sum);
    int lsum = 0, rsum = 0, lmax = -1, rmax = -1;
    for(int i = mid; i >= l; i-- ) {
        lsum += a[i];
        lmax = max(lmax, lsum);
    }
    for(int i = mid + 1; i <= r; i++ ) {
        rsum += a[i];
        rmax = max(rmax, rsum);
    }
    return max(sum, lmax+rmax);
}
 
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%d",a+i);
    }
    int ans = dfs(0, n-1);
    printf("%d %d\n", ans , cnt);
    return 0;
}



//D – 骨牌铺方格*
//3
//3
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
LL dp[111];
LL dfs(int n) {
    if(dp[n]) return dp[n];
    if(n == 1 || n == 0) return 1;
    return dp[n] = dfs(n-1) + dfs(n-2);
}
 
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    printf("%lld\n", dfs(n));
    return 0;
}
//非递归
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
LL f[1111] = {0, 1, 2};
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    for (int i = 3; i <= n; i++) f[i] = f[i - 1] + f[i - 2];
    printf("%lld\n", f[n]);
    return 0;
}



//A – 高数Umaru系列（9）——哈士奇
/*2 100
50 20
60 40
3 100
20 55
20 35
90 95
1 10
20 50*/
//40  95  0
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int val[111], w[111];
int dp[1111];
int main(int argc, char const *argv[]) {
    int n, m;
    while(cin >> n >> m) {
        memset(dp, 0, sizeof dp);
        for (int i = 1; i <= n; i++) scanf("%d %d", w + i, val + i);
        for (int i = 1; i <= n; i++) {
            for (int j = m; j >= w[i]; j--)
                dp[j] = max(dp[j], dp[j - w[i]] + val[i]);
        }
        printf("%d\n", dp[m]);
    }
    return 0;
}



//B – 最少硬币问题
//3 1 3 2 3 5 3 18 
//5 
#include <bits/stdc++.h>
const int maxn = 2e4+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int v[maxn], has[maxn];
int dp[maxn];
int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%d %d",v+i, has+i);
    cin >> m;
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = m; j >= v[i]; j--) {
            for(int k = 0; k <= has[i]; k++) {
                if(j - k * v[i] >= 0)
                dp[j] = min(dp[j], dp[j - k * v[i]] + k);
            }
        }
    }
    printf("%d\n", dp[m] == inf ? -1 : dp[m]);
    return 0;
}



//C – 数字三角形问题
//5   7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 
//30 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int dp[111][111], a[111][111];
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= i; j++) {
            scanf("%d",&a[i][j]);
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= i; j++) {
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + a[i][j];
            ans = max(ans, dp[i][j]);
        }
    }
    printf("%d\n", ans);
    return 0;
}




D – 石子合并问题*
//4  4 4 5 9 
//43 54 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int a[222];
int dp1[222][222], dp2[222][222], sum[222];
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    memset(dp2, 0x3f, sizeof dp2);
    for(int i = 1; i <= n; i++) scanf("%d",a+i), a[i+n] = a[i];
    for(int i = 1; i <= n*2; i++) {
        sum[i] = sum[i-1] + a[i];
        dp1[i][i] = dp2[i][i] = 0;
    }
    for(int len = 2; len <= n; len ++) {
        for(int l = 1; l + len - 1 <= 2 * n; l ++) {
            int r = l + len - 1;
            for(int k = l; k < r; k++) {
                dp1[l][r] = max(dp1[l][k] + dp1[k+1][r] + sum[r] - sum[l-1], dp1[l][r]);
                dp2[l][r] = min(dp2[l][k] + dp2[k+1][r] + sum[r] - sum[l-1], dp2[l][r]);
            }
        }
    }
    int ans1 = -1, ans2 = inf;
    for(int i = 1; i <= n; i++) {
        ans1 = max(ans1, dp1[i][i+n-1]);
        ans2 = min(ans2, dp2[i][i+n-1]);
    }
    printf("%d\n%d\n",ans2, ans1);
    return 0;
}




E – 最长公共子序列问题*
//ABCBDAB BDCABA 
//4 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
char x[555], y[555];
int dp[555][555];
int main(int argc, char const *argv[]) {
    while(~scanf("%s%s",x+1,y+1)) {
        memset(dp, 0, sizeof dp);
        int n = strlen(x+1), m = strlen(y+1);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (x[i] == y[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        printf("%d\n", dp[n][m]);
    }
    return 0;
}
 



 // A – 汽车加油问题*
//7 7 1 2 3 4 5 1 6 6 
//4 
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int a[maxn];
int main(int argc, char const *argv[]) {
    int n, p;
    cin >> p >> n;
    n++;
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    int ans = 0, now = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > p) {
            puts("No Solution!");
            exit(0);
        }
        if (now + a[i] > p) {
            ans++;
            now = 0;
        }
        now += a[i];
    }
    printf("%d\n", ans);
    return 0;
}





//B – 多元Huffman编码问题*
//7 3   45 13 12 16 9 5 22 
//593 199 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
 
int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    priority_queue<LL> qb, qs;
    for(int i = 0; i < n; i++) {
        LL x;
        scanf("%lld",&x);
        qb.push(x);
        qs.push(-x);
    }
    LL ans1 = 0, ans2 = 0;
    while(qb.size() > 1) {
        LL x = qb.top();
        qb.pop();
        LL y = qb.top();
        qb.pop();
        ans1 += x + y;
        qb.push(x + y);
    }
    while(qs.size()%(k-1)!=1)  qs.push(0);
    while(qs.size() > 1) {
        LL temp = 0;
        for(int i = 0; i < k; i++) {
 
            temp -= qs.top();
            qs.pop();
        }
        ans2 += temp;
        qs.push(-temp);
    }
    printf("%lld %lld\n", ans1, ans2);
    return 0;
}
 




//C – 装船问题
//100 10 10 20 10 30 10 40 10 50 10 60 10 70 10 80 10 90 10 100 10 
//550 
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
struct node {
    int p, w;
    double bi;
    bool operator<(const node &t) const { return bi > t.bi; }
} a[1211];
 
int main(int argc, char const *argv[]) {
    int m;
    cin >> m;
    for (int i = 0; i < 10; i++)
        scanf("%d %d", &a[i].p, &a[i].w), a[i].bi = a[i].p * 1.0 / a[i].w;
    sort(a, a + 10);
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        if (m - a[i].w >= 0) {
            ans += a[i].p;
            m -= a[i].w;
        } else {
            ans += a[i].bi * m;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}




//D – 活动选择
//6    8 10 9 16 11 16 14 15 10 14 7 11 
//1,5,4 
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
struct node {
    int id, st, ed;
    bool operator<(const node &t) const {
        if(ed == t.ed) return id < t.id;
        return ed < t.ed;
    }
} a[1211];
 
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        scanf("%d %d", &a[i].st, &a[i].ed), a[i].id = i + 1;
    sort(a,a+n);
    int now = 0;
    vector<int> ans;
    for(int i = 0; i < n; i++) {
        if(now <= a[i].st) {
            ans.push_back(a[i].id);
            now = a[i].ed;
        }
    }
    for(int i = 0; i < ans.size(); i++) printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ',');
    return 0;
}






//E – 最优合并问题
//4   5 12 11 2 
//78 52 
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
 
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    priority_queue<int> q1, q2;
    for(int i = 0; i < n; i++ ){
        int x; scanf("%d",&x);
        q1.push(-x);
        q2.push(x);
    }
    int ans1 = 0, ans2 = 0;
    while(q1.size() > 1) {
        int x = q1.top();
        q1.pop();
        int y = q1.top();
        q1.pop();
        ans1 -= x + y + 1;
        q1.push(x+y);
    }
    while(q2.size() > 1) {
        int x = q2.top();
        q2.pop();
        int y = q2.top();
        q2.pop();
        ans2 += x + y - 1;
        q2.push(x+y);
    }
    printf("%d %d\n",ans2, ans1);
    return 0;
}





//F – 区间覆盖问题
//7 3     1 2 3 4 5 -2 6 
//3 
#include <bits/stdc++.h>
const int maxn = 1e4+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int a[maxn];
int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) scanf("%d", a + i); 
    sort(a,a+n);
    int now = a[0], cnt = 1;
    for(int i = 1; i < n; i++ ) {
        if(now + k >= a[i]) continue;
        now = a[i];
        cnt++;
    }
    printf("%d",cnt);
    return 0;
}




//A – 子集和问题*
//5 10      2 2 6 5 4 
//2 2 6 
#include <bits/stdc++.h>
const int maxn = 1e4+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int n, c;
int ans[maxn], a[maxn], m, f;
void dfs(int i, int sum, int pos){
    if(sum > c || f == 1) return;
    if(sum == c) {
        f = 1;
        for(int i = 0; i < pos; i++) printf("%d%c", ans[i], i == pos - 1 ? '\n' : ' ');
        return;
    }
    for(; i < n; i++) {
        if(a[i] + sum <= c) {
            ans[pos] = a[i];
            dfs(i + 1, sum + a[i], pos + 1);
        }
    }
}
int main(int argc, char const *argv[]) {
    cin >> n >> c;
    int sum = 0;
    for(int i = 0; i < n; i++) scanf("%d", a + i), sum += a[i];
    if(sum < c) puts("No Solution!");
    else {
        dfs(0,0,0);
        if(!f) puts("No Solution!");
    }
    return 0;
}





//B – 运动员最佳匹配问题*
// 3    10 2 3   2 3 4   3 4 5   2 2 2   3 5 3   4 5 1 
//52
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int ans, vis[111], sum;
int n;
int p[111][111], q[111][111], a[111];
 
void dfs(int i) {
    if(i == n) {
        ans = max(ans, sum);
        return;
    }
    int temp = 0;
    for(int j = i; j < n; j++) {
        temp += a[j];
    }
    if(sum + temp <= ans) return;
    for(int j = 0; j < n; j++) {
        if(vis[j] == 0) {
            ////////////////////////////  恢复现场
            vis[j] = 1;
            sum += p[i][j] * q[j][i];
            dfs(i+1);
            sum -= p[i][j] * q[j][i];
            vis[j] = 0;
            ////////////////////////////  恢复现场
        }
    }
}
int main(int argc, char const *argv[]) {
    cin >> n;
    for(int i = 0; i < n; i++) 
        for(int j = 0; j < n; j++) {
            scanf("%d", &p[i][j]);
        }
    for(int i = 0; i < n; i++) 
        for(int j = 0; j < n; j++) scanf("%d", &q[i][j]);
    for(int i = 0; i < n; i++) 
        for(int j = 0; j < n; j++) a[i] = max(a[i], p[i][j] * q[j][i]);
    dfs(0);
    printf("%d",ans);
    return 0;
}



//C – 工作分配问题
// 3    10 2 3   2 3 4   3 4 5 
//9
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int n;
int a[111][111], b[111], ans = inf, vis[111], sum;
void dfs(int i) {
    if (i == n) {
        ans = min(sum, ans);
        return;
    }
    int temp = 0;
    for (int j = i; j < n; j++) temp += b[j];
    if (temp + sum >= ans) return;
    for (int j = 0; j < n; j++) {
        if (!vis[j]) {
            vis[j] = 1;
            sum += a[i][j];
            dfs(i + 1);
            vis[j] = 0;
            sum -= a[i][j];
        }
    }
}
int main(int argc, char const *argv[]) {
    cin >> n;
    memset(b, 0x3f, sizeof b);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &a[i][j]), b[i] = min(b[i], a[i][j]);
    dfs(0);
    printf("%d", ans);
    return 0;
}
 




//D – 整数变换问题*
//15 4 
//4 gfgg 
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
typedef long long LL;
typedef pair<LL, int> PII;
int ans;
int n, m;
char s[maxn];
bool dfs(int sum, int ceng) {
    if (ceng + 1 > ans) return 0;
    if (sum * 3 == m || dfs(sum * 3, ceng + 1)) {
        s[ceng] = 'f';
        return 1;
    }
    if (sum / 2 == m || dfs(sum / 2, ceng + 1)) {
        s[ceng] = 'g';
        return 1;
    }
    return 0;
}
int main(int argc, char const *argv[]) {
    cin >> n >> m;
    while (!dfs(n, 0)) ans++;
    printf("%d\n", ans);
    for (int i = ans - 1; i >= 0; i--) printf("%c", s[i]);
    return 0;
}





